/*
* 科技有限公司版权所有（）.
* Copyright (c) 2019, and/or its affiliates. All rights reserved.
* @Date: 2020.07.22 10:38.
* @Author
* @Description  登录
**/
<template>
  <div class="pr-login">
    <h3>欢迎登录</h3>
    <el-form :model="form" label-width="0" ref="form" class="pr-form">

      <el-form-item label="">
        <i class="el-icon-user-solid"></i>
        <el-input v-model="form.userName" placeholder="请输入用户名"></el-input>
      </el-form-item>

      <el-form-item label="">
        <i class="el-icon-lock"></i>
        <el-input v-model="form.password" placeholder="请输入密码"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button @click="handleLoginClick" type="primary">登 录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import urls from '@/api/urls'
import { postData, getData } from '@/api/'

export default {
  name: 'EditInfo',
  props: {},
  components: {},
  data() {
    return {
      form: {
        userName: '', // 13109509969 @123456
        password: '', // Jhuk@173
      },
    }
  },
  watch: {},
  mounted() {
  },
  created() { },
  methods: {
    /**
     *@Description
     *@Return 登录.
     **/
    handleLoginClick() {
      if (this.form.userName.trim() === '' || this.form.password.trim() === '') {
        this.$message.warning('请输入用户名或密码！')
        return false
      }

      postData({ username: this.form.userName, password: this.form.password }, urls.loginUrl).then(res => {
        console.log('登录接口----', res)
        if (res.code == '0') {
          localStorage.setItem('userName', this.form.userName)
          localStorage.setItem('Authorization', res.result.token)

          this.getMenuInfo() // 获取权限列表
        } else {
          this.$message.warning(res.message)
          return false
        }
      }).catch(err => {
        this.$message.warning(err.message)
      })
      console.log('保存配置', this.form, this.$router)
    },
    /**
     *@Description
     *@Return 获取权限列表.
     **/
    getMenuInfo() {
      getData({}, urls.menuInfoUrl).then(res => {
        console.log('获取权限列表----', res.result)
        localStorage.setItem('menusStr', JSON.stringify(res.result.menus))
        this.$router.push('/activityList')
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.pr-login {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  color: #fff;
  background: #041527;
  h3 {
    margin: 100px auto 50px auto;
    font-size: 30px;
    text-align: center;
  }
}
.pr-form {
  width: 400px;
  margin: 50px auto;
  ::v-deep .el-form-item__content {
    position: relative;
  }
  i {
    position: absolute;
    top: 10px;
    left: 13px;
    z-index: 1;
    font-size: 20px;
    color: #999;
  }
  .el-button {
    width: 100%;
  }
  ::v-deep .el-input__inner,
  ::v-deep .el-input {
    height: 40px !important;
    line-height: 40px !important;
    margin-bottom: 20px;
  }
  ::v-deep .el-input__inner {
    text-indent: 2em;
  }
}
</style>
